<?php
// 查询oa_admin_rule表数据的脚本

// 数据库连接配置
$host = '127.0.0.1';
$dbname = 'oa5';
$username = 'root';
$password = '123456';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // 查询菜单数据
    $sql = "SELECT id, src, title, module FROM oa_admin_rule WHERE src != '' AND menu = 1 AND status = 1 ORDER BY module, id";
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    
    echo "菜单数据:\n";
    echo str_repeat("-", 80) . "\n";
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        printf("ID: %d, Module: %-10s, Src: %-30s, Title: %s\n", 
               $row['id'], $row['module'], $row['src'], $row['title']);
    }
    
    // 统计各模块数据量
    $sql2 = "SELECT module, COUNT(*) as count FROM oa_admin_rule WHERE src != '' AND menu = 1 AND status = 1 GROUP BY module ORDER BY count DESC";
    $stmt2 = $pdo->prepare($sql2);
    $stmt2->execute();
    
    echo "\n各模块菜单数量统计:\n";
    echo str_repeat("-", 30) . "\n";
    while ($row = $stmt2->fetch(PDO::FETCH_ASSOC)) {
        printf("Module: %-10s Count: %d\n", $row['module'], $row['count']);
    }
    
} catch(PDOException $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

echo "\n查询完成。\n";